__author__ = 'pcJxy'

from rsa import *
import hashlib


def sign_message(msg: bytes, key: int, n: int):
    md5_digest = hashlib.md5(msg).digest()
    return rsa_encrypt(md5_digest, key, n)


def is_signature_valid(msg: bytes, signature: bytes, key: int, n: int):
    decrypted_md5_digest = rsa_decrypt(signature, key, n)
    msg_md5_digest = hashlib.md5(msg).digest()
    return decrypted_md5_digest == msg_md5_digest
